home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / ip / trace / tcpdump-2.2.1 / print-udp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-22  |  4.1 KB  |  142 lines

  1. /*
  2.  * Copyright (c) 1988-1990 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that: (1) source code distributions
  7.  * retain the above copyright notice and this paragraph in its entirety, (2)
  8.  * distributions including binary code include the above copyright notice and
  9.  * this paragraph in its entirety in the documentation or other materials
  10.  * provided with the distribution, and (3) all advertising materials mentioning
  11.  * features or use of this software display the following acknowledgement:
  12.  * ``This product includes software developed by the University of California,
  13.  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  14.  * the University nor the names of its contributors may be used to endorse
  15.  * or promote products derived from this software without specific prior
  16.  * written permission.
  17.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  18.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  19.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20.  */
  21.  
  22. #ifndef lint
  23. static char rcsid[] =
  24.     "@(#) $Header: print-udp.c,v 1.26 92/05/22 19:43:17 leres Exp $ (LBL)";
  25. #endif
  26.  
  27. #include <sys/param.h>
  28. #include <sys/types.h>
  29. #include <sys/socket.h>
  30. #include <netinet/in.h>
  31. #include <netinet/in_systm.h>
  32. #include <netinet/ip.h>
  33. #include <netinet/ip_var.h>
  34. #include <netinet/udp.h>
  35. #include <netinet/udp_var.h>
  36.  
  37. #include <arpa/nameser.h>
  38. #include <arpa/tftp.h>
  39. #include <errno.h>
  40. #include <sys/time.h>
  41. #include <rpc/types.h>
  42. #include <rpc/auth.h>
  43. #include <rpc/auth_unix.h>
  44. #include <rpc/svc.h>
  45. #include <rpc/xdr.h>
  46. #include <rpc/rpc_msg.h>
  47.  
  48. #include "interface.h"
  49. /* These must come after interface.h for BSD. */
  50. #if BSD >= 199006
  51. #include <sys/ucred.h>
  52. #include <nfs/nfsv2.h>
  53. #endif
  54. #include <nfs/nfs.h>
  55.  
  56. #include "addrtoname.h"
  57. #include "appletalk.h"
  58.  
  59. #include "bootp.h"
  60.  
  61. /* XXX probably should use getservbyname() and cache answers */
  62. #define TFTP_PORT 69        /*XXX*/
  63. #define SUNRPC_PORT 111        /*XXX*/
  64. #define SNMP_PORT 161        /*XXX*/
  65. #define NTP_PORT 123        /*XXX*/
  66. #define SNMPTRAP_PORT 162    /*XXX*/
  67. #define RIP_PORT 520        /*XXX*/
  68.  
  69. void
  70. udp_print(up, length, ip)
  71.     register struct udphdr *up;
  72.     int length;
  73.     register struct ip *ip;
  74. {
  75.     register u_char  *cp = (u_char *)(up + 1);
  76.  
  77.     if (cp > snapend) {
  78.         printf("[|udp]");
  79.         return;
  80.     }
  81.     if (length < sizeof(struct udphdr)) {
  82.         (void)printf(" truncated-udp %d", length);
  83.         return;
  84.     }
  85.     length -= sizeof(struct udphdr);
  86.  
  87.     NTOHS(up->uh_sport);
  88.     NTOHS(up->uh_dport);
  89.     NTOHS(up->uh_ulen);
  90.  
  91.     if (! qflag) {
  92.         register struct rpc_msg *rp;
  93.         enum msg_type direction;
  94.  
  95.         rp = (struct rpc_msg *)(up + 1);
  96.         direction = (enum msg_type)ntohl(rp->rm_direction);
  97.         if (up->uh_dport == NFS_PORT && direction == CALL) {
  98.             nfsreq_print(rp, length, ip);
  99.             return;
  100.         }
  101.         else if (up->uh_sport == NFS_PORT && direction == REPLY) {
  102.             nfsreply_print(rp, length, ip);
  103.             return;
  104.         }
  105. #ifdef notdef
  106.         else if (up->uh_dport == SUNRPC_PORT && direction == CALL) {
  107.             sunrpcrequest_print(rp, length, ip);
  108.             return;
  109.         }
  110. #endif
  111.         else if (cp[2] == 2 && (atalk_port(up->uh_sport) ||
  112.              atalk_port(up->uh_dport))) {
  113.             ddp_print((struct atDDP *)(&cp[3]), length - 3);
  114.             return;
  115.         }
  116.     }
  117.     (void)printf("%s.%s > %s.%s:",
  118.         ipaddr_string(&ip->ip_src), udpport_string(up->uh_sport),
  119.         ipaddr_string(&ip->ip_dst), udpport_string(up->uh_dport));
  120.  
  121.     if (!qflag) {
  122. #define ISPORT(p) (up->uh_dport == (p) || up->uh_sport == (p))
  123.         if (ISPORT(NAMESERVER_PORT))
  124.             ns_print((HEADER *)(up + 1), length);
  125.         else if (ISPORT(TFTP_PORT))
  126.             tftp_print((struct tftphdr *)(up + 1), length);
  127.         else if (ISPORT(IPPORT_BOOTPC) || ISPORT(IPPORT_BOOTPS))
  128.             bootp_print((struct bootp *)(up + 1), length,
  129.                 up->uh_sport, up->uh_dport);
  130.         else if (up->uh_dport == RIP_PORT)
  131.             rip_print((u_char *)(up + 1), length);
  132.         else if (ISPORT(SNMP_PORT) || ISPORT(SNMPTRAP_PORT))
  133.             snmp_print((u_char *)(up + 1), length);
  134.         else if (ISPORT(NTP_PORT))
  135.             ntp_print((struct ntpdata *)(up + 1), length);
  136.         else
  137.             (void)printf(" udp %d", up->uh_ulen - sizeof(*up));
  138. #undef ISPORT
  139.     } else
  140.         (void)printf(" udp %d", up->uh_ulen - sizeof(*up));
  141. }
  142.